package gui;


import java.awt.Color;
import java.awt.Component;
import java.io.File;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import javax.swing.UIDefaults;
import javax.swing.filechooser.FileSystemView;

import logic.file.IDirectory;
import logic.file.IFile;

public class FileListCellRenderer implements ListCellRenderer<IFile> {
	
	private static final Icon fileIconBig = new ImageIcon("./images/icons/fileIconBig.gif");
	private static final Icon dirIconBig = new ImageIcon("./images/icons/dirIconBig.gif");
	
	
	
	private static final UIDefaults defaults = javax.swing.UIManager.getDefaults(); 

	@Override
	public Component getListCellRendererComponent(JList<? extends IFile> list,
			IFile value, int index, boolean isSelected, boolean cellHasFocus) {
		
		JLabel label = new JLabel( value.getName() );
		label.setOpaque(true);
		//label.set
		
		if (isSelected) {
			
			label.setBackground(defaults.getColor("Table.selectionBackground"));
		
		} else {
		
			label.setBackground(Color.WHITE);
		
		}																		
		if ( value instanceof IDirectory ) {
			label.setIcon(dirIconBig);
		} else {
			label.setIcon(fileIconBig);
		}
		
		label.setHorizontalTextPosition(JLabel.CENTER);
		label.setVerticalTextPosition(JLabel.BOTTOM);
		label.setIconTextGap(0);
		//label.setBorder(BorderFactory.createEmptyBorder());
		return label;
	}

}
